﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using MP.LayerHelper.MP_OBS.BLL;
using MP.LayerHelper.MP_OBS.DAL.EntityClasses;
using MP.LayerHelper.MP_OBS.DAL.HelperClasses;

using MP.Core.Config;
using MP.Core.Library;
public partial class Admin_Hurman_Controls_ListJobTitle : MP.Core.Authentication.Control.AuthenBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        InitAuthen(EnumModules.JOBTITLE);
        if (!IsPostBack)
            loadData();
    }

    void loadData()
    {
        DataSet dst = HrJobTitleManager.CreateInstant().GetAllJob();
        repJob.DataSource = dst;
        repJob.DataBind();
    }


    protected void repJob_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "del":
                HrJobTitleEntity job = HrJobTitleManager.CreateInstant().GetById(new Guid(e.CommandArgument.ToString()));
                if (job != null)
                {
                    job.IsDeleted = true;
                    job.UpdatedDate = DateTime.Now;
                    job.UpdatedBy = Util.CurrentUserName;
                    HrJobTitleManager.CreateInstant().Update(job);
                    Response.Redirect(Request.RawUrl);
                }
                break;
            case "edit":
                for (int i = 0; i < repJob.Items.Count; i++)
                {
                    TextBox txt = (TextBox)repJob.Items[i].FindControl("txtPriority");
                    HiddenField hid = (HiddenField)repJob.Items[i].FindControl("hidJobId");
                    int k = 0;
                    if (int.TryParse(txt.Text.Trim(), out k) && Util.IsGuid(hid.Value))
                    {
                        HrJobTitleManager.CreateInstant().UpdatePriority(new Guid(hid.Value), k);
                    }
                }
                Response.Redirect(Request.RawUrl);
                break;
        }
    }
}
